package main

import (
	"google.golang.org/grpc"
	"net"
	"net/http"
	"runtime"
	"user-server/src/biz"
	bizImpl "user-server/src/biz/impl"
	"user-server/src/boot"
	"user-server/src/repo"
	"user-server/src/repo/impl"
	"user-server/src/server"
	"user-server/src/util/logs"
	pb "user-server/user"

	_ "net/http/pprof"
)

func main() {
	boot.EnableAll()

	biz.InjectUserCacheService(&bizImpl.UserCacheServiceImpl{Redis: boot.GetRedisEngine()})
	repo.InjectUserInfoDao(&impl.UserInfoDaoImpl{DbEngine: boot.GetOrmEngine()})

	//pprof分析使用
	runtime.SetBlockProfileRate(1)
	go func() {
		http.ListenAndServe(":10001", nil)
	}()

	lis, err := net.Listen("tcp", "localhost:5000")
	if err != nil {
		logs.Error("cannot create a listener at the address")
	}

	grpcServer := grpc.NewServer()
	pb.RegisterUserServiceServer(grpcServer, &server.UserServer{})

	err = grpcServer.Serve(lis)
	// TODO
	if err != nil {
		logs.Error("cannot create a listener at the address")
	}
}
